package com.wink_172.library.utils

import android.content.Context
import com.tencent.mmkv.MMKV

/**
 * 腾讯开发的
 * 类似于 SharedPreferencesTool使用方式
 * 但是更加精简高效的存储方式
 *
 */
object MMKVTool {
    @JvmStatic
    fun getInt(context: Context?, key: String?, defValue: Int): Int {
        val kv = MMKV.defaultMMKV()
        return kv!!.decodeInt(key, defValue) //取
    }
    @JvmStatic
    fun setInt(context: Context?, key: String?, value: Int) {
        val kv = MMKV.defaultMMKV()
        kv!!.encode(key, value)
    }
    @JvmStatic
    fun getFloat(context: Context?, key: String?, defValue: Float): Float {
        val kv = MMKV.defaultMMKV()
        return kv!!.decodeFloat(key, defValue) //取
    }
    @JvmStatic
    fun setFloat(context: Context?, key: String?, value: Float) {
        val kv = MMKV.defaultMMKV()
        kv!!.encode(key, value)
    }
    @JvmStatic
    fun getLong(context: Context?, key: String?, defValue: Long?): Long {
        val kv = MMKV.defaultMMKV()
        return kv!!.decodeLong(key, defValue!!) //取
    }
    @JvmStatic
    fun setLong(context: Context?, key: String?, value: Long) {
        val kv = MMKV.defaultMMKV()
        kv!!.encode(key, value)
    }

    @JvmStatic
    fun getString(context: Context?, key: String?, defValue: String?): String? {
        val kv = MMKV.defaultMMKV()
        return kv!!.decodeString(key, defValue) //取
    }

    @JvmStatic
    fun setString(context: Context?, key: String?, value: String?) {
        val kv = MMKV.defaultMMKV()
        kv!!.encode(key, value)
    }
    @JvmStatic
    fun getBoolean(context: Context?, key: String?, defValue: Boolean?): Boolean {
        val kv = MMKV.defaultMMKV()
        return kv!!.decodeBool(key, defValue!!) //取
    }
    @JvmStatic
    fun setBoolean(context: Context?, key: String?, value: Boolean?) {
        val kv = MMKV.defaultMMKV()
        kv!!.encode(key, value!!)
    }
    @JvmStatic
    fun remove(context: Context?, key: String?) {
        val kv = MMKV.defaultMMKV()
        kv!!.remove(key)
    }
    @JvmStatic
    fun clear(context: Context?) {
        val kv = MMKV.defaultMMKV()
        kv!!.clearAll()
    }
}